package com.community.web.master.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.community.model.entity.Charge;
import com.community.model.entity.ChargeDetail;
import com.community.web.master.domain.dto.PageChargeDto;
import com.community.web.master.domain.vo.ChargeDetailVo;
import com.community.web.master.domain.vo.ChargeWithUserVo;
import com.community.web.master.domain.vo.PageResult;
import com.community.web.master.mapper.ChargeDetailMapper;
import com.community.web.master.mapper.ChargeMapper;
import com.community.web.master.mapper.UserMapper;
import com.community.web.master.service.IChargeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 李晶
 * @since 2024-07-02
 */
@Service
public class ChargeServiceImpl extends ServiceImpl<ChargeMapper, Charge> implements IChargeService {
    @Autowired
    private ChargeMapper chargeMapper;
    @Autowired
    private ChargeDetailMapper chargeDetailMapper;

    /**
     * 分页查询
     * @param pageChargeDto
     * @return
     */
    public PageResult pageQuery(PageChargeDto pageChargeDto) {
        QueryWrapper<Charge> queryWrapper=pageChargeDto.getChargeStatus()==null?
                new QueryWrapper<Charge>() : new QueryWrapper<Charge>().eq("charge_status",pageChargeDto.getChargeStatus());

        Map<String,Integer> map=new HashMap<>();
        map.put("limit",(pageChargeDto.getPageSize()));
        map.put("offset",(pageChargeDto.getPage()-1)*pageChargeDto.getPageSize());
        map.put("chargeStatus",pageChargeDto.getChargeStatus());

        Long total = chargeMapper.selectCount(queryWrapper);
        List<ChargeWithUserVo> result= chargeMapper.selectPageByMap(map);

        return new PageResult(total,result);
    }

    /**
     * 根据订单号查询订单详情
     * @param chargeNo
     * @return
     */
    @Override
    public List<ChargeDetail> getDetailListByChargeNo(String chargeNo) {
        QueryWrapper<ChargeDetail> queryWrapper = new QueryWrapper<ChargeDetail>();
        queryWrapper.eq("charge_no",chargeNo);
        List<ChargeDetail> chargeDetails = chargeDetailMapper.selectList(queryWrapper);
        return chargeDetails;
    }
}
